﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AuroraWuBi
{
   public class WordMakingCode
    {
        private Dictionary<string, string> _WordDit;//所有单字构词码

        public Dictionary<string, string> WordDit
        {
            get
            {
                return _WordDit;
            }
        }

        /// <summary>
        /// 生成唯一构词码
        /// </summary>
        /// <param name="_word"></param>
        /// <param name="_code">汉字完整编码</param>
        public void AddWordMakingCode(string _word, string _code)
        {
            //System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[\u4e00-\u9fa5]{1}$");
            //if (!regex.IsMatch(_word))
            //    return;

            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[A-Za-z]{2,4}$");
            if (!regex.IsMatch(_code))
                return;

            _code = _code.ToLower().Substring(0, 2);
            if (_WordDit == null)
            {
                _WordDit = new Dictionary<string, string>();
                _WordDit.Add(_word, _code);
            }
            else
            {
                if (!_WordDit.ContainsKey(_word))
                {
                    _WordDit.Add(_word, _code);
                }
            }
        }
    }
}
